package day01.wc

import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author wsl
 * @Description  local模式
 * 两种区别：Driver运行的地方不同
 * local：driver运行在client本地，如果是本地idea执行的，localhost:4040
 * yarn：driver运行在yarn集群，
 */
object WC_local {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setAppName("wc").setMaster("local[*]")
    val sc = new SparkContext(conf)

    sc.textFile("sparkcore/input/1.txt")
      .flatMap(line => line.split(" "))
      .map(word => (word, 1))
      .reduceByKey((v1, v2) => v1 + v2)
      .collect()
      .foreach(println)

    sc.textFile("sparkcore/input/1.txt")
      .flatMap(_.split(" "))
      .map( (_, 1))
      .reduceByKey(_+_)
      .collect()
      .foreach(println)

    Thread.sleep(Long.MaxValue)
    sc.stop()
  }
}
